if [ -n "`which include.sh`" ]; then echo "including `which include.sh`";. `which include.sh`; fi
local_path=`dirname ${0}`

function setup-xwiki.sh()
{
echoTextBlue "setup-xwiki.sh"
}

function setup-mediawiki.sh()
{
    echoTextBlue "Begain to setup mediawiki ......"
    sh_dpkg_install "apache2"
    sh_dpkg_install "mysql-server mysql-client"   #(中间要求设置密码，记住你设置的密码)
    sh_dpkg_install "libgd2-xpm libgd2-xpm-dev"
    sh_dpkg_install "php5-common=5.3.3-1ubuntu9 php5 php5-mysql  php5-gd"
    sh_dpkg_install "mediawiki"

    echoTextBlue "Configurate mediawiki ......" 
    echoTextBlue "去掉 #Alias /wiki /var/lib/mediawiki 的注释符 #"
    sudo sh -c 'sed -i "/#Alias/s/#//g" /etc/mediawiki/apache.conf'
    if test -w /var/lib/mediawiki; then
      echoTextGreen "not root user"
      sh_svn_up --url http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/CategoryTree /var/lib/mediawiki/extensions/CategoryTree -r 51817
      sh_svn_up --url http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/FCKeditor /var/lib/mediawiki/extensions/FCKeditor   
      return
      sh_wget http://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.2/ckeditor_3.6.2.tar.gz ~/downloads/
      tar -xvf ~/downloads/ckeditor_3.6.2.tar.gz -C /var/lib/mediawiki/extensions/FCKeditor/fckeditor  
    else
      echoTextGreen "root user"
      sudo sh -c 'sh_svn_up http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/CategoryTree /var/lib/mediawiki/extensions/CategoryTree'
      sudo sh -c 'sh_svn_up http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/FCKeditor /var/lib/mediawiki/extensions/FCKeditor'
      sh_wget http://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.2/ckeditor_3.6.2.tar.gz ~/downloads/
      sudo sh -c 'tar -xvf ~/downloads/ckeditor_3.6.2.tar.gz -C /var/lib/mediawiki/extensions/FCKeditor/fckeditor/'
    fi
    echoTextBlue "配置 CategoryTree 控件......"
    #$wgUseAjax = true;
    #require_once("$IP/extensions/CategoryTree/CategoryTree.php");
    echoTextBlue "配置 FCKeditor 控件......"
    #require_once("$IP/extensions/FCKeditor/FCKeditor.php");
    #execel 插件
    #http://www.bestbai.info/wordpress/wp-content/uploads/2011/06/Excelviewer.zip


    sudo /etc/init.d/apache2 restart
    return
#架设Wikipedia的本地镜像
#http://note.sdo.com/u/1557869253/n/sSPb5~jxCyQMLX01k00a75
折腾了很久，终于搞清楚mediawiki树状显示子分类的办法了：安装categorytree插件即可，下载地址以及安装方法，链接如下：
http://www.mediawiki.org/wiki/Extension:CategoryTree
http://blog.u-you.net/2011/09/mediawiki--树状分类控件/
http://blog.u-you.net/2011/09/mediawiki-%E6%A0%91%E7%8A%B6%E5%88%86%E7%B1%BB%E6%8E%A7%E4%BB%B6/
}

function server()
{
server_name=tracd
server_cmd=
#!/bin/bash
case "$1" in
start)
    echo "start $server_name server"
    
    echo -n " $server_name"
    ;;
stop)
    echo "stop $server_name server"
    ac_pid=`pidof lmgrd`
    kill $ac_pid 2>> ${LOG} 1>&2
    ac_pid=`pidof $server_name`
    kill $ac_pid 2>> ${LOG} 1>&2
    ;;
restart)
    echo "restart lmgrd server"
    ac_pid=`pidof lmgrd`
    kill $ac_pid 2>> ${LOG} 1>&2
    ac_pid=`pidof armlmd`
    kill $ac_pid 2>> ${LOG} 1>&2

    lmgrd -c ${LICENSE_FILE} 2>> ${LOG} 1>&2
    echo -n " lmgrd"
    ;; 
*)
    echo "Usage: `basename $0` {start|stop|restart}" 1>&2
    exit 64
    ;;
esac
}


function setup-trac.sh()
{
    #*  Python：版本必须 >= 2.4 并且 < 3.0
    #*  setuptools：版本 >= 0.6。在 这里下载对应 Python 版本及平台的包，这里下载的是 setuptools-0.6c11-py2.6.egg。使用以下命令安装：
    #  sh setuptools-0.6c11-py2.6.egg
    #*  Genshi：版本 >= 0.6。安装好 setuptools 以后，以下安装其他的就很容易了，输入以下命令安装：
    #  easy_install Genshi
    #*  Subversion：版本无要求，当前使用版本为 1.6.x。还需要安装 SVN 的 Python 包才能使 Trac 读取 SVN 数据，使用以下命令安装：
    #  apt-get install python-subversion
    remote_setuptools="http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086"
    echoTextBlue "Begain to setup trac ......"
    if test ! -f ~/downloads/setuptools-0.6c11-py2.6.egg; then
	sh_wget $remote_setuptools  ~/downloads/
    fi
    result=`which easy_install`
    if [ -z "$result" ]; then
        if test -f ~/downloads/setuptools-0.6c11-py2.6.egg; then
	    sh ~/downloads/setuptools-0.6c11-py2.6.egg
        else
            return
        fi
    fi
    #安装  python-setuptools  否则 easy_install Genshi 等出错
    sudo apt-get install python-setuptools   
    result=`which easy_install`
    if [ -n "$result" ]; then
        easy_install Genshi
    fi
    sh_dpkg_install "python-subversion"

    #*  Babel：版本 >= 0.9.5，提供本地化支持。Trac 有中文界面（但帮助没有汉化），但注意必须在安装 Trac 之前安装此包，否则只能显示英文界面。
    #*  docutils：版本 >= 0.3.9，用于 WikiRestructuredText。
    #*  Pygments ：用于语法高亮。 
    result=`which pygmentize`
    if [ -z "$result" ]; then
        easy_install Babel docutils Pygments
    fi
    #用 easy_install 命令安装，指定安装最新稳定版本 0.12： 
    if [ -n "$result" ]; then
        easy_install Trac==0.12
    fi
    #项目环境就是存储 Trac 所有后台数据的一个目录。初始化配置 Trac 项目环境使用以下命令：
    mkdir ~/www/trac/ -pv
    if test -d ~/www/trac/; then
        result=`question "Are you reinit ~/www/trac/ ？" 1 no`
        if [  "$result" = "yes" ] ; then
            trac-admin ~/www/trac/ initenv
        fi
    else
	trac-admin ~/www/trac/ initenv
    fi
    result=`question "Are you run tracd？" 1 yes`
    if [  "$result" = "yes" ] ; then
        tracd -s --port 8000 ~/www/trac/&
    fi 
}

function wiki-help.sh()
{
echoTextBlue "
Alias /mediawiki /var/lib/mediawiki
http://127.0.0.1/mediawiki"

   
}


#脚步入口：解析参数
while test $# != 0
do
    case $1 in
	-r)
	    shift
	    version=$1
	    ;;
	-m)
	    shift
	    mode=$1
	    ;;
        *)
	    mode=$1
	    ;;
       esac
       shift
done

if [ "$mode" == "auto" ]; then
    echo "auto"
    setup-mediawiki.sh
    setup-trac.sh
    wiki-help.sh
else
    menu_list="
setup-xwiki.sh
setup-mediawiki.sh
setup-trac.sh
wiki-help.sh"
    echoTextBlue "Please select"
    result=`sh_menu_select "$menu_list"`
    echo "${result}"
    ${result}
fi



